<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">






  
  
  <link rel="stylesheet" media="all" href="/lib/Han/dist/han.min.css?v=3.3">




<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/img/icon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/img/icon.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="cayun's blog, IT, ACM/ICPC, blog, cayun" />










<meta property="og:type" content="website">
<meta property="og:title" content="cayun&#39;s blog">
<meta property="og:url" content="http://localhost/page/6/index.html">
<meta property="og:site_name" content="cayun&#39;s blog">
<meta property="og:locale" content="zh-Hans">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="cayun&#39;s blog">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://localhost/page/6/"/>





  <title>cayun's blog</title>
  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-93052608-1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?1ca7c9c8011b37b0c209724dc77c24db";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
  page-home">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">cayun's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">不积跬步, 无以至千里!</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://localhost/gym101173A/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="cayun">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/head.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="cayun's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/gym101173A/" itemprop="url">Gym 101173A Appearance Analysis (暴力)</a></h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-07-01T00:00:00+08:00">
                2017-07-01
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/gym101173A/#SOHUCS" itemprop="discussionUrl">
                  <span id="url::http://localhost/gym101173A/" class="cy_cmt_count" data-xid="gym101173A/" itemprop="commentsCount" ></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        
          
            <h1 id="解法"><a href="#解法" class="headerlink" title="解法"></a>解法</h1><p>直接暴力比较即可，注意长宽相同的情况需要比较四个方向。</p>
<h1 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h1><figure class="highlight cpp"><table><tr><td class="code"><pre><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></div><div class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</div><div class="line"></div><div class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">120</span>;</div><div class="line"><span class="keyword">char</span> s[N][N];</div><div class="line"><span class="keyword">int</span> n, m, r, c;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">getPoint</span><span class="params">(<span class="keyword">int</span> &amp;x, <span class="keyword">int</span> &amp;y, <span class="keyword">int</span> p)</span> </span>&#123;</div><div class="line">    <span class="keyword">int</span> lineNum = (c - <span class="number">1</span>) / (m + <span class="number">1</span>);</div><div class="line">    <span class="keyword">int</span> idx = p / lineNum;</div><div class="line">    <span class="keyword">int</span> idy = p % lineNum;</div><div class="line">    x = (n + <span class="number">1</span>) * idx + <span class="number">2</span>;</div><div class="line">    y = (m + <span class="number">1</span>) * idy + <span class="number">2</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">bool</span> <span class="title">theSame</span><span class="params">(<span class="keyword">int</span> p1, <span class="keyword">int</span> p2)</span> </span>&#123;</div><div class="line">    <span class="keyword">int</span> x1, y1, x2, y2;</div><div class="line">    getPoint(x1, y1, p1);</div><div class="line">    getPoint(x2, y2, p2);</div><div class="line"></div><div class="line">    <span class="keyword">bool</span> flag = <span class="literal">true</span>;</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; i++) &#123;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; m; j++) &#123;</div><div class="line">            <span class="keyword">if</span> (s[x1 + i][y1 + j] != s[x2 + i][y2 + j]) &#123;</div><div class="line">                flag = <span class="literal">false</span>;</div><div class="line">                <span class="keyword">break</span>;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">if</span> (!flag) <span class="keyword">break</span>;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">if</span> (flag) <span class="keyword">return</span> <span class="literal">true</span>;</div><div class="line"></div><div class="line">    flag = <span class="literal">true</span>;</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; i++) &#123;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; m; j++) &#123;</div><div class="line">            <span class="keyword">if</span> (s[x1+i][y1+j] != s[x2+n<span class="number">-1</span>-i][y2+m<span class="number">-1</span>-j]) &#123;</div><div class="line">                flag = <span class="literal">false</span>;</div><div class="line">                <span class="keyword">break</span>;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">if</span> (!flag) <span class="keyword">break</span>;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">if</span> (flag) <span class="keyword">return</span> <span class="literal">true</span>;</div><div class="line"></div><div class="line">    <span class="keyword">if</span> (n != m) <span class="keyword">return</span> <span class="literal">false</span>;</div><div class="line"></div><div class="line">    flag = <span class="literal">true</span>;</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; i++) &#123;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; n; j++) &#123;</div><div class="line">            <span class="keyword">if</span> (s[x1+i][y1+j] != s[x2+j][y2+n<span class="number">-1</span>-i]) &#123;</div><div class="line">                flag = <span class="literal">false</span>;</div><div class="line">                <span class="keyword">break</span>;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">if</span> (!flag) <span class="keyword">break</span>;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">if</span> (flag) <span class="keyword">return</span> <span class="literal">true</span>;</div><div class="line"></div><div class="line">    flag = <span class="literal">true</span>;</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; i++) &#123;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; n; j++) &#123;</div><div class="line">            <span class="keyword">if</span> (s[x1+i][y1+j] != s[x2+n<span class="number">-1</span>-j][y2+i]) &#123;</div><div class="line">                flag = <span class="literal">false</span>;</div><div class="line">                <span class="keyword">break</span>;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">if</span> (!flag) <span class="keyword">break</span>;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">return</span> flag;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</div><div class="line">    <span class="keyword">while</span> (<span class="built_in">scanf</span>(<span class="string">"%d%d"</span>, &amp;r, &amp;c) != EOF) &#123;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= r; i++)</div><div class="line">            <span class="built_in">scanf</span>(<span class="string">"%s"</span>, s[i] + <span class="number">1</span>);</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">2</span>; i &lt;= r; i++) &#123;</div><div class="line">            <span class="keyword">if</span> (s[i][<span class="number">2</span>] == <span class="string">'#'</span>) &#123;</div><div class="line">                n = i - <span class="number">2</span>;</div><div class="line">                <span class="keyword">break</span>;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">2</span>; i &lt;= c; i++) &#123;</div><div class="line">            <span class="keyword">if</span> (s[<span class="number">2</span>][i] == <span class="string">'#'</span>) &#123;</div><div class="line">                m = i - <span class="number">2</span>;</div><div class="line">                <span class="keyword">break</span>;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">int</span> sum = ((r - <span class="number">1</span>) / (n + <span class="number">1</span>)) * ((c - <span class="number">1</span>) / (m + <span class="number">1</span>));</div><div class="line">        <span class="keyword">int</span> ans = <span class="number">0</span>;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; sum; i++) &#123;</div><div class="line">            <span class="keyword">bool</span> flag = <span class="literal">true</span>;</div><div class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; i; j++) &#123;</div><div class="line">                <span class="keyword">if</span> (theSame(j, i)) &#123;</div><div class="line">                    flag = <span class="literal">false</span>;</div><div class="line">                    <span class="keyword">break</span>;</div><div class="line">                &#125;</div><div class="line">            &#125;</div><div class="line">            <span class="keyword">if</span> (flag) ans++;</div><div class="line">        &#125;</div><div class="line">        <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, ans);</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://localhost/gym101173K/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="cayun">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/head.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="cayun's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/gym101173K/" itemprop="url">Gym 101173K Key Knocking (构造)</a></h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-07-01T00:00:00+08:00">
                2017-07-01
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/gym101173K/#SOHUCS" itemprop="discussionUrl">
                  <span id="url::http://localhost/gym101173K/" class="cy_cmt_count" data-xid="gym101173K/" itemprop="commentsCount" ></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        
          
            <h1 id="解法"><a href="#解法" class="headerlink" title="解法"></a>解法</h1><p>一道构造题，目标是修改$n$次使得weight至少为$2n$。<br>那么我们可以每$3$位数一考虑。<br>对于$010$和$101$我们可以不用修改就可以达到要求。<br>对于$001, 011, 100, 110$我们只需要修改一次就可以变为$010$或$101$。<br>那么剩下的就是$000$和$111$了。由于对称性，我们只讨论$000$。<br>假设$000$已经是这串字符串的最后三位了，那么很简单，因为最终的总权重会再加上$1$，所以只需要修改成$011$即可。<br>若不是最后三位，那我们就继续加上接下来的三位来进行讨论:<br>$000000,000001,000010,000011,000100,000101,000110$这些我们可以很容易通过至多两次变换就使得不同的数对有$4$个。<br>那么还剩下$000111$的情况，同理，以及以$111$开头的$111000$的情况。这个时候再向后考虑三位即可。</p>
<h1 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h1><figure class="highlight cpp"><table><tr><td class="code"><pre><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></div><div class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</div><div class="line"></div><div class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">300005</span>;</div><div class="line"><span class="keyword">char</span> s[N];</div><div class="line"><span class="keyword">int</span> ans[N];</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">bool</span> <span class="title">strequ</span><span class="params">(<span class="keyword">int</span> i, <span class="keyword">const</span> <span class="keyword">char</span> *ss)</span> </span>&#123;</div><div class="line">    <span class="keyword">int</span> j = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">    <span class="keyword">return</span> s[j] == ss[<span class="number">0</span>] &amp;&amp; s[j+<span class="number">1</span>] == ss[<span class="number">1</span>] &amp;&amp; s[j+<span class="number">2</span>] == ss[<span class="number">2</span>];</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</div><div class="line">    <span class="keyword">while</span> (<span class="built_in">scanf</span>(<span class="string">"%s"</span>, s + <span class="number">1</span>) != EOF) &#123;</div><div class="line">        <span class="keyword">int</span> n = <span class="built_in">strlen</span>(s + <span class="number">1</span>);</div><div class="line">        <span class="keyword">int</span> m = n / <span class="number">3</span>;</div><div class="line">        <span class="keyword">int</span> cnt = <span class="number">0</span>;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= m; i++) &#123;</div><div class="line">            <span class="comment">//printf("i = %d\n", i);</span></div><div class="line">            <span class="keyword">if</span> (strequ(i, <span class="string">"001"</span>) || strequ(i, <span class="string">"110"</span>)) &#123; <span class="comment">//001和110</span></div><div class="line">                ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i, <span class="string">"100"</span>) || strequ(i, <span class="string">"011"</span>)) &#123; <span class="comment">//100和011</span></div><div class="line">                ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i, <span class="string">"000"</span>)) &#123;</div><div class="line">                <span class="keyword">if</span> (i == m) &#123;   <span class="comment">//以000结尾</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">                    <span class="keyword">continue</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"000"</span>)) &#123;  <span class="comment">//000000</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span>;</div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"001"</span>)) &#123; <span class="comment">//000001</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> + <span class="number">2</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"010"</span>)) &#123; <span class="comment">//000010</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"011"</span>)) &#123; <span class="comment">//000011</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> + <span class="number">1</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"100"</span>)) &#123; <span class="comment">//000100</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> + <span class="number">1</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"101"</span>)) &#123; <span class="comment">//000101</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"110"</span>)) &#123; <span class="comment">//000110</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span>;</div><div class="line">                &#125; <span class="keyword">else</span> &#123; <span class="comment">//000111</span></div><div class="line">                    <span class="keyword">if</span> (i + <span class="number">1</span> == m) &#123; <span class="comment">//以000111结尾</span></div><div class="line">                        ans[++cnt] = i * <span class="number">3</span>;</div><div class="line">                    &#125; <span class="keyword">else</span> &#123;</div><div class="line">                        <span class="keyword">if</span> (strequ(i + <span class="number">2</span>, <span class="string">"001"</span>) || strequ(i + <span class="number">2</span>, <span class="string">"010"</span>) || strequ(i + <span class="number">2</span>, <span class="string">"100"</span>)) &#123;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span>;</div><div class="line">                        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">2</span>, <span class="string">"011"</span>) || strequ(i + <span class="number">2</span>, <span class="string">"101"</span>) || strequ(i + <span class="number">2</span>, <span class="string">"110"</span>)) &#123;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> + <span class="number">2</span>;</div><div class="line">                        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">2</span>, <span class="string">"000"</span>)) &#123; <span class="comment">//000111000</span></div><div class="line">                            ans[++cnt] = i * <span class="number">3</span>;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> + <span class="number">3</span>;</div><div class="line">                            i++;</div><div class="line">                        &#125; <span class="keyword">else</span> &#123; <span class="comment">//000111111</span></div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> + <span class="number">2</span>;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> + <span class="number">3</span>;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">                            i++;</div><div class="line">                        &#125;</div><div class="line">                    &#125;</div><div class="line">                &#125;</div><div class="line">                i++;</div><div class="line">            &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i, <span class="string">"111"</span>)) &#123;</div><div class="line">                <span class="keyword">if</span> (i == m) &#123; <span class="comment">//以111结尾</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"001"</span>)) &#123; <span class="comment">//111001</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> + <span class="number">2</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"010"</span>)) &#123; <span class="comment">//111010</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"011"</span>)) &#123; <span class="comment">//111011</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> + <span class="number">1</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"100"</span>)) &#123; <span class="comment">//111100</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> + <span class="number">1</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"101"</span>)) &#123; <span class="comment">//111101</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"110"</span>)) &#123; <span class="comment">//111110</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">                &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">1</span>, <span class="string">"111"</span>)) &#123; <span class="comment">//111111</span></div><div class="line">                    ans[++cnt] = i * <span class="number">3</span>;</div><div class="line">                    ans[++cnt] = i * <span class="number">3</span> - <span class="number">1</span>;</div><div class="line">                &#125; <span class="keyword">else</span> &#123; <span class="comment">//111000</span></div><div class="line">                    <span class="keyword">if</span> (i + <span class="number">1</span> == m) &#123; <span class="comment">//以111000结尾</span></div><div class="line">                        ans[++cnt] = i * <span class="number">3</span>;</div><div class="line">                    &#125; <span class="keyword">else</span> &#123;</div><div class="line">                        <span class="keyword">if</span> (strequ(i + <span class="number">2</span>, <span class="string">"001"</span>) || strequ(i + <span class="number">2</span>, <span class="string">"010"</span>) || strequ(i + <span class="number">2</span>, <span class="string">"100"</span>)) &#123;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> + <span class="number">2</span>;</div><div class="line">                        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">2</span>, <span class="string">"011"</span>) || strequ(i + <span class="number">2</span>, <span class="string">"101"</span>) || strequ(i + <span class="number">2</span>, <span class="string">"110"</span>)) &#123;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span>;</div><div class="line">                        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (strequ(i + <span class="number">2</span>, <span class="string">"000"</span>)) &#123; <span class="comment">//111000000</span></div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> + <span class="number">2</span>;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> + <span class="number">3</span>;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> - <span class="number">2</span>;</div><div class="line">                            i++;</div><div class="line">                        &#125; <span class="keyword">else</span> &#123; <span class="comment">//111000111</span></div><div class="line">                            ans[++cnt] = i * <span class="number">3</span>;</div><div class="line">                            ans[++cnt] = i * <span class="number">3</span> + <span class="number">3</span>;</div><div class="line">                            i++;</div><div class="line">                        &#125;</div><div class="line">                    &#125;</div><div class="line">                &#125;</div><div class="line">                i++;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, cnt);</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= cnt; i++) &#123;</div><div class="line">            <span class="built_in">printf</span>(<span class="string">"%d%c"</span>, ans[i], i == cnt ? <span class="string">'\n'</span> : <span class="string">' '</span>);</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://localhost/gym101243C/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="cayun">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/head.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="cayun's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/gym101243C/" itemprop="url">Gym 101243C Desktop (构造)</a></h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-29T00:00:00+08:00">
                2017-06-29
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/gym101243C/#SOHUCS" itemprop="discussionUrl">
                  <span id="url::http://localhost/gym101243C/" class="cy_cmt_count" data-xid="gym101243C/" itemprop="commentsCount" ></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        
          
            <h1 id="解法"><a href="#解法" class="headerlink" title="解法"></a>解法</h1><p>我们首先可以计算出可能的最大数量，首先一定会有一个全部都能显示，剩下的至少能显示一半，那么最大数量就是$(n * m - 4) / 2 + 1$，化简一下就是$n * m / 2 - 1$个。于是我们发现很容易就可以构造出最大数量的情况。</p>
<h1 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h1><figure class="highlight cpp"><table><tr><td class="code"><pre><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></div><div class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</div><div class="line">    freopen(<span class="string">"input.txt"</span>, <span class="string">"r"</span>, <span class="built_in">stdin</span>);</div><div class="line">    freopen(<span class="string">"output.txt"</span>, <span class="string">"w"</span>, <span class="built_in">stdout</span>);</div><div class="line">    <span class="keyword">int</span> h, w; <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>, &amp;h, &amp;w);</div><div class="line">    <span class="keyword">if</span> (h &gt;= <span class="number">2</span> &amp;&amp; w &gt;= <span class="number">2</span>) &#123;</div><div class="line">        <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, h * w / <span class="number">2</span> - <span class="number">1</span>);</div><div class="line">        <span class="keyword">if</span> (w % <span class="number">2</span> == <span class="number">0</span>) &#123;</div><div class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = h - <span class="number">1</span>; i &gt;= <span class="number">2</span>; i--) &#123;</div><div class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">1</span>; j &lt;= w; j += <span class="number">2</span>)</div><div class="line">                    <span class="built_in">printf</span>(<span class="string">"%d %d\n"</span>, i, j);</div><div class="line">            &#125;</div><div class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; w; i++)</div><div class="line">                <span class="built_in">printf</span>(<span class="string">"%d %d\n"</span>, <span class="number">1</span>, i);</div><div class="line">        &#125; <span class="keyword">else</span> <span class="keyword">if</span> (h % <span class="number">2</span> == <span class="number">0</span>) &#123;</div><div class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> j = w - <span class="number">1</span>; j &gt;= <span class="number">2</span>; j--) &#123;</div><div class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= h; i += <span class="number">2</span>) </div><div class="line">                    <span class="built_in">printf</span>(<span class="string">"%d %d\n"</span>, i, j);</div><div class="line">            &#125;</div><div class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; h; i++)</div><div class="line">                <span class="built_in">printf</span>(<span class="string">"%d %d\n"</span>, i, <span class="number">1</span>);</div><div class="line">        &#125; <span class="keyword">else</span> &#123;</div><div class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">3</span>; i &lt; h; i += <span class="number">2</span>) &#123;</div><div class="line">                <span class="built_in">printf</span>(<span class="string">"%d %d\n"</span>, i, w - <span class="number">1</span>);</div><div class="line">            &#125;</div><div class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = h - <span class="number">1</span>; i &gt;= <span class="number">2</span>; i--) &#123;</div><div class="line">                <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">1</span>; j &lt; w; j += <span class="number">2</span>) </div><div class="line">                    <span class="built_in">printf</span>(<span class="string">"%d %d\n"</span>, i, j);</div><div class="line">            &#125;</div><div class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; w; i++)</div><div class="line">                <span class="built_in">printf</span>(<span class="string">"%d %d\n"</span>, <span class="number">1</span>, i);</div><div class="line">        &#125;</div><div class="line">    &#125; <span class="keyword">else</span> &#123;</div><div class="line">        <span class="built_in">printf</span>(<span class="string">"0\n"</span>);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://localhost/gym101243J/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="cayun">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/head.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="cayun's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/gym101243J/" itemprop="url">Gym 101243J Architect of Your Own Fortune (二分图匹配)</a></h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-29T00:00:00+08:00">
                2017-06-29
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/gym101243J/#SOHUCS" itemprop="discussionUrl">
                  <span id="url::http://localhost/gym101243J/" class="cy_cmt_count" data-xid="gym101243J/" itemprop="commentsCount" ></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        
          
            <h1 id="解法"><a href="#解法" class="headerlink" title="解法"></a>解法</h1><p>一道二分图匹配裸题，直接上板子。</p>
<h1 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h1><figure class="highlight cpp"><table><tr><td class="code"><pre><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></div><div class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</div><div class="line"></div><div class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">110</span>;</div><div class="line"><span class="keyword">int</span> a[N], b[N];</div><div class="line"><span class="keyword">int</span> n, m;</div><div class="line"></div><div class="line"><span class="comment">//匈牙利算法模板</span></div><div class="line"><span class="keyword">bool</span> g[N][N], used[N];<span class="comment">//编号是0~n-1的 </span></div><div class="line"><span class="keyword">int</span> linker[N];</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">bool</span> <span class="title">DFSHungary</span><span class="params">(<span class="keyword">int</span> u)</span> </span>&#123;</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> v = <span class="number">0</span>; v &lt; m; v++) &#123;</div><div class="line">        <span class="keyword">if</span> (g[u][v] &amp;&amp; !used[v]) &#123;</div><div class="line">            used[v] = <span class="literal">true</span>;</div><div class="line">            <span class="keyword">if</span> (linker[v] == <span class="number">-1</span> || DFSHungary(linker[v])) &#123;</div><div class="line">                linker[v] = u;</div><div class="line">                <span class="keyword">return</span> <span class="literal">true</span>;</div><div class="line">            &#125;    </div><div class="line">        &#125; </div><div class="line">    &#125; </div><div class="line">    <span class="keyword">return</span> <span class="literal">false</span>;  </div><div class="line">&#125;    </div><div class="line"></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">Hungary</span><span class="params">()</span> </span>&#123;</div><div class="line">    <span class="keyword">int</span> res = <span class="number">0</span>;</div><div class="line">    <span class="built_in">memset</span>(linker, <span class="number">-1</span>, <span class="keyword">sizeof</span>(linker));</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> u = <span class="number">0</span>; u &lt; n; u++) &#123;</div><div class="line">        <span class="built_in">memset</span>(used, <span class="number">0</span>, <span class="keyword">sizeof</span>(used));</div><div class="line">        <span class="keyword">if</span> (DFSHungary(u)) res++;</div><div class="line">    &#125; </div><div class="line">    <span class="keyword">return</span> res;   </div><div class="line">&#125; </div><div class="line"></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">isOk</span><span class="params">(<span class="keyword">int</span> i, <span class="keyword">int</span> j)</span> </span>&#123;</div><div class="line">    <span class="keyword">if</span> (a[i] / <span class="number">100000</span> + a[i] % <span class="number">100000</span> / <span class="number">10000</span> + a[i] % <span class="number">10000</span> / <span class="number">1000</span> </div><div class="line">        == b[j] % <span class="number">100</span> / <span class="number">10</span> + b[j] % <span class="number">1000</span> / <span class="number">100</span> + b[j] % <span class="number">10</span>) &#123;</div><div class="line">        <span class="keyword">return</span> <span class="number">1</span>;</div><div class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span> (a[i] % <span class="number">10</span> + a[i] % <span class="number">100</span> / <span class="number">10</span> + a[i] % <span class="number">1000</span> / <span class="number">100</span> </div><div class="line">        == b[j] / <span class="number">100000</span> + b[j] % <span class="number">100000</span> / <span class="number">10000</span> + b[j] % <span class="number">10000</span> / <span class="number">1000</span>) &#123;</div><div class="line">        <span class="keyword">return</span> <span class="number">2</span>;</div><div class="line">    &#125; <span class="keyword">else</span> &#123;</div><div class="line">        <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</div><div class="line">    freopen(<span class="string">"input.txt"</span>, <span class="string">"r"</span>, <span class="built_in">stdin</span>);</div><div class="line">    freopen(<span class="string">"output.txt"</span>, <span class="string">"w"</span>, <span class="built_in">stdout</span>);</div><div class="line">    <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>, &amp;n, &amp;m);</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; i++)</div><div class="line">        <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &amp;a[i]);</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; m; i++)</div><div class="line">        <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &amp;b[i]);</div><div class="line">    <span class="built_in">memset</span>(g, <span class="literal">false</span>, <span class="keyword">sizeof</span>(g));</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; n; i++) </div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j &lt; m; j++) &#123;</div><div class="line">        <span class="keyword">if</span> (isOk(i, j) &gt; <span class="number">0</span>) &#123;</div><div class="line">            g[i][j] = <span class="literal">true</span>;</div><div class="line">            <span class="comment">//printf("%d %d\n", i, j);</span></div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line">    <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, Hungary());</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; m; i++) &#123;</div><div class="line">        <span class="keyword">if</span> (linker[i] != <span class="number">-1</span>) &#123;</div><div class="line">            <span class="keyword">if</span> (isOk(linker[i], i) == <span class="number">1</span>) &#123;</div><div class="line">                <span class="built_in">printf</span>(<span class="string">"AT %06d %06d\n"</span>, a[linker[i]], b[i]);</div><div class="line">            &#125; <span class="keyword">else</span> &#123;</div><div class="line">                <span class="built_in">printf</span>(<span class="string">"TA %06d %06d\n"</span>, b[i], a[linker[i]]);</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://localhost/gym101243G/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="cayun">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/head.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="cayun's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/gym101243G/" itemprop="url">Gym 101243G Sphenic numbers (质因数分解)</a></h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-29T00:00:00+08:00">
                2017-06-29
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/gym101243G/#SOHUCS" itemprop="discussionUrl">
                  <span id="url::http://localhost/gym101243G/" class="cy_cmt_count" data-xid="gym101243G/" itemprop="commentsCount" ></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        
          
            <h1 id="解法"><a href="#解法" class="headerlink" title="解法"></a>解法</h1><p>就是一道质因数分解裸题。</p>
<h1 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h1><figure class="highlight cpp"><table><tr><td class="code"><pre><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></div><div class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">bool</span> <span class="title">isPrime</span><span class="params">(<span class="keyword">int</span> u)</span> </span>&#123;</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">2</span>; i * i &lt;= u; i++) &#123;</div><div class="line">        <span class="keyword">if</span> (u % i == <span class="number">0</span>) <span class="keyword">return</span> <span class="literal">false</span>;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">return</span> <span class="literal">true</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</div><div class="line">    freopen(<span class="string">"input.txt"</span>, <span class="string">"r"</span>, <span class="built_in">stdin</span>);</div><div class="line">    freopen(<span class="string">"output.txt"</span>, <span class="string">"w"</span>, <span class="built_in">stdout</span>);</div><div class="line">    <span class="keyword">int</span> n; <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &amp;n);</div><div class="line">    <span class="keyword">bool</span> flag = <span class="literal">true</span>;</div><div class="line">    <span class="keyword">int</span> num = <span class="number">0</span>, cur = <span class="number">2</span>;</div><div class="line">    <span class="keyword">while</span> (n &gt; <span class="number">1</span>) &#123;</div><div class="line">        <span class="keyword">if</span> (cur * cur &gt; n) <span class="keyword">break</span>;</div><div class="line">        <span class="keyword">if</span> (n % cur == <span class="number">0</span>) &#123;</div><div class="line">            num++;</div><div class="line">            n /= cur;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">if</span> (n % cur == <span class="number">0</span>) &#123;</div><div class="line">            flag = <span class="literal">false</span>;</div><div class="line">            <span class="keyword">break</span>;</div><div class="line">        &#125;</div><div class="line">        cur++;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">if</span> (isPrime(n)) &#123;</div><div class="line">        num++;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">if</span> (flag &amp;&amp; num == <span class="number">3</span>) <span class="built_in">puts</span>(<span class="string">"YES"</span>);</div><div class="line">    <span class="keyword">else</span> <span class="built_in">puts</span>(<span class="string">"NO"</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://localhost/gym101243E/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="cayun">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/head.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="cayun's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/gym101243E/" itemprop="url">Gym 101243E Cupcakes  (博弈+暴力)</a></h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-29T00:00:00+08:00">
                2017-06-29
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/gym101243E/#SOHUCS" itemprop="discussionUrl">
                  <span id="url::http://localhost/gym101243E/" class="cy_cmt_count" data-xid="gym101243E/" itemprop="commentsCount" ></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        
          
            <h1 id="解法"><a href="#解法" class="headerlink" title="解法"></a>解法</h1><p>我们不妨贪吃鬼为$a<em>{p}$，$p-1$为left，$\sum</em>{i=1}^{p-1} a<em>{i}$为right，$n-1+a</em>{p}$为deltaLeft，$\sum a_{i}$为deltaRight。那么不难发现只要$k$属于$[left + deltaLeft * x, right + deltaRight * x]$，那么就可以满足条件，否则不能满足条件。然后时间刚好够暴力枚举到最后。</p>
<h1 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h1><figure class="highlight cpp"><table><tr><td class="code"><pre><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></div><div class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</div><div class="line"></div><div class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> LL;</div><div class="line"></div><div class="line"><span class="keyword">const</span> <span class="keyword">int</span> N = <span class="number">100005</span>;</div><div class="line">LL a[N];</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</div><div class="line">    freopen(<span class="string">"input.txt"</span>, <span class="string">"r"</span>, <span class="built_in">stdin</span>);</div><div class="line">    freopen(<span class="string">"output.txt"</span>, <span class="string">"w"</span>, <span class="built_in">stdout</span>);</div><div class="line">    <span class="keyword">int</span> n; LL k;</div><div class="line">    <span class="built_in">scanf</span>(<span class="string">"%d%lld"</span>, &amp;n, &amp;k);</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= n; i++) &#123;</div><div class="line">        <span class="built_in">scanf</span>(<span class="string">"%lld"</span>, &amp;a[i]);</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">int</span> p = <span class="number">1</span>;</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">2</span>; i &lt;= n; i++) &#123;</div><div class="line">        <span class="keyword">if</span> (a[i] &gt; a[p]) p = i;</div><div class="line">    &#125;</div><div class="line">    LL l = p - <span class="number">1</span>, r = <span class="number">0</span>;</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt; p; i++) &#123;</div><div class="line">        r += a[i];</div><div class="line">    &#125; </div><div class="line">    LL dl = a[p] + n - <span class="number">1</span>, dr = <span class="number">0</span>;</div><div class="line">    <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= n; i++) &#123;</div><div class="line">        dr += a[i]; </div><div class="line">    &#125;</div><div class="line">    <span class="keyword">bool</span> flag = <span class="literal">false</span>;</div><div class="line">    <span class="keyword">while</span> (l &lt;= k) &#123;</div><div class="line">        <span class="keyword">if</span> (l &lt;= k &amp;&amp; k &lt;= r) &#123;</div><div class="line">            flag = <span class="literal">true</span>;</div><div class="line">            <span class="keyword">break</span>;</div><div class="line">        &#125;</div><div class="line">        l += dl;</div><div class="line">        r += dr;</div><div class="line">        <span class="keyword">if</span> (r &gt; k) r = k;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">if</span> (flag) <span class="built_in">puts</span>(<span class="string">"YES"</span>);</div><div class="line">    <span class="keyword">else</span> <span class="built_in">puts</span>(<span class="string">"KEK"</span>);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://localhost/codeforces821E/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="cayun">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/head.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="cayun's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/codeforces821E/" itemprop="url">codeforces 821E Okabe and El Psy Kongroo (DP+矩阵快速幂)</a></h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-26T00:00:00+08:00">
                2017-06-26
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/ACM-ICPC/" itemprop="url" rel="index">
                    <span itemprop="name">ACM/ICPC</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/codeforces821E/#SOHUCS" itemprop="discussionUrl">
                  <span id="url::http://localhost/codeforces821E/" class="cy_cmt_count" data-xid="codeforces821E/" itemprop="commentsCount" ></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        
          <h1 id="解法"><a href="#解法" class="headerlink" title="解法"></a>解法</h1><p>对于第$i$列，设其所对应的高度为$c$，那么我们可以很容易地发现第$i$列可以由第$i-1$列得出。即使$i$刚好位于$b<em>{k-1},a</em>{k}$的交界处，那么其实仔细想想可以发现这个规律依然成立。若$c<em>{k-1} &lt; c</em>{k}$，那么可以将前一列的$c<em>{k-1}+1 \sim c</em>{k}$部分作为$0$来计算，若$c<em>{k-1} &gt; c</em>{k}$，那么前一列的$c<em>{k}+1 \sim c</em>{k-1}$部分将不参与计算。想通这些之后，其实这题的思路就已经有了。那么我们的解法就是对于每一段$a<em>{k},b</em>{k}$都分别进行DP，DP方程可以很容易地通过矩阵来进行加速。</p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/codeforces821E/" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://localhost/codeforces821C/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="cayun">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/head.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="cayun's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/codeforces821C/" itemprop="url">codeforces 821C Okabe and Boxes (贪心)</a></h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-26T00:00:00+08:00">
                2017-06-26
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/ACM-ICPC/" itemprop="url" rel="index">
                    <span itemprop="name">ACM/ICPC</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/codeforces821C/#SOHUCS" itemprop="discussionUrl">
                  <span id="url::http://localhost/codeforces821C/" class="cy_cmt_count" data-xid="codeforces821C/" itemprop="commentsCount" ></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        
          <h1 id="解法"><a href="#解法" class="headerlink" title="解法"></a>解法</h1><p>这题的思路很简单，就是当我们遇到remove时，若栈顶元素是我们所需要的那个元素，那我们就弹出栈顶元素，否则就将剩下的部分从小到大排序即可。<br>但是每次都做排序显然是不行的，这时候我们可以考虑设置一个数据结构，表示里面的元素都已经是有序的了，而且支持添加和删除操作，显然这个时候set就很适合。那么对于未排序的部分，我们只需要在设置一个stack来保存即可。这样的话，我们优先使用stack里面的元素，然后再使用set里面的元素，若stack顶部元素不满足弹出要求就将stack里面的元素全部放进set中。<br>注：实际编程中发现其实用不到set，只是辅助理解即可。</p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/codeforces821C/" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://localhost/codeforces821D/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="cayun">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/head.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="cayun's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/codeforces821D/" itemprop="url">codeforces 821D Okabe and City (搜索+剪枝)</a></h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-26T00:00:00+08:00">
                2017-06-26
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/ACM-ICPC/" itemprop="url" rel="index">
                    <span itemprop="name">ACM/ICPC</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/codeforces821D/#SOHUCS" itemprop="discussionUrl">
                  <span id="url::http://localhost/codeforces821D/" class="cy_cmt_count" data-xid="codeforces821D/" itemprop="commentsCount" ></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        
          <h1 id="解法"><a href="#解法" class="headerlink" title="解法"></a>解法</h1><p>首先可以发现这一题其实就是一个从$(1,1)$位置开始的搜索题，设当前位置为$u$，从$(1,1)$到$u$需要消耗的硬币为$dis<em>{u}$，那对于$u$连通的所有位置其消耗的硬币都为$dis</em>{u}$，对于与$u$同行或邻行或隔一行的位置所需要消耗的硬币数则为$dis_{u}+1$。对于列同样。由于我们是对行和列进行操作，所以我们可以记录行和列是否访问过，以防止重复访问。<br>注：对于终点(原先不亮的情况)只能是同行或同列或邻行或邻列才可以进行访问</p>
          <!--noindex-->
          <div class="post-button text-center">
            <a class="btn" href="/codeforces821D/" rel="contents">
              阅读全文 &raquo;
            </a>
          </div>
          <!--/noindex-->
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://localhost/ural1068/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="cayun">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/img/head.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="cayun's blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/ural1068/" itemprop="url">ural 1068 Sum (暴力)</a></h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-06-24T00:00:00+08:00">
                2017-06-24
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
              <span class="post-meta-divider">|</span>
              <span class="post-meta-item-icon">
                <i class="fa fa-comment-o"></i>
              </span>
              
                <a href="/ural1068/#SOHUCS" itemprop="discussionUrl">
                  <span id="url::http://localhost/ural1068/" class="cy_cmt_count" data-xid="ural1068/" itemprop="commentsCount" ></span>
                </a>
              
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        
          
            <h1 id="解法"><a href="#解法" class="headerlink" title="解法"></a>解法</h1><p>直接从$1$加到$x(x &gt;= 1)$或从$x$加到$1(x &lt; 1)$即可。</p>
<h1 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h1><figure class="highlight cpp"><table><tr><td class="code"><pre><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;bits/stdc++.h&gt;</span></span></div><div class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span> </span>&#123;</div><div class="line">    <span class="keyword">int</span> x; <span class="built_in">cin</span> &gt;&gt; x;</div><div class="line">    <span class="keyword">int</span> ans = <span class="number">0</span>;</div><div class="line">    <span class="keyword">if</span> (x &gt;= <span class="number">1</span>) &#123;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &lt;= x; i++) </div><div class="line">            ans += i;</div><div class="line">    &#125; <span class="keyword">else</span> &#123;</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i &gt;= x; i--)</div><div class="line">            ans += i;</div><div class="line">    &#125;</div><div class="line">    <span class="built_in">cout</span> &lt;&lt; ans &lt;&lt; <span class="string">"\n"</span>;</div><div class="line">    <span class="keyword">return</span> <span class="number">0</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/5/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/5/">5</a><span class="page-number current">6</span><a class="page-number" href="/page/7/">7</a><span class="space">&hellip;</span><a class="page-number" href="/page/11/">11</a><a class="extend next" rel="next" href="/page/7/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/img/head.png"
                alt="cayun" />
            
              <p class="site-author-name" itemprop="name">cayun</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">102</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">79</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/comeacrossyun" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:comeacrossyun@gmail.com" target="_blank" title="E-Mail">
                    
                      <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
            
          </div>

          
          

          
          

          

        </div>
      </section>

      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">cayun</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a></div>




        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.3"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  




	





  





  




  
    <script id="cy_cmt_num" src="https://changyan.sohu.com/upload/plugins/plugins.list.count.js?clientId=cyt6VLWhj"></script>
  









  





  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  
  

  
  
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
  


  

  

</body>
</html>
